package com.ruoyi.system.service.impl;

import java.util.Date;
import java.util.List;

import com.ruoyi.common.security.utils.SecurityUtils;
import com.ruoyi.db.domain.system.MpClient;
import com.ruoyi.db.domain.system.MpTeamApply;
import com.ruoyi.db.mapper.system.MpClientMapper;
import com.ruoyi.db.mapper.system.MpTeamApplyMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.system.service.IMpTeamApplyService;

import javax.transaction.Transactional;

/**
 * 【商城用户】Service业务层处理
 * 
 * @author ruoyi
 * @date 2022-07-23
 */
@Service
@Transactional(rollbackOn = Exception.class)
public class MpTeamApplyServiceImpl implements IMpTeamApplyService 
{
    @Autowired
    private MpTeamApplyMapper mpTeamApplyMapper;
    @Autowired
    private MpClientMapper mpClientMapper;

    /**
     * 查询【商城用户】
     * 
     * @param teamApplyId 【商城用户】主键
     * @return 【商城用户】
     */
    @Override
    public MpTeamApply selectMpTeamApplyByTeamApplyId(Long teamApplyId)
    {
        return mpTeamApplyMapper.selectMpTeamApplyByTeamApplyId(teamApplyId);
    }

    /**
     * 查询【商城用户】列表
     * 
     * @param mpTeamApply 【商城用户】
     * @return 【商城用户】
     */
    @Override
    public List<MpTeamApply> selectMpTeamApplyList(MpTeamApply mpTeamApply)
    {
        return mpTeamApplyMapper.selectMpTeamApplyList(mpTeamApply);
    }

    /**
     * 新增【商城用户】
     * 
     * @param mpTeamApply 【商城用户】
     * @return 结果
     */
    @Override
    public int insertMpTeamApply(MpTeamApply mpTeamApply)
    {
        return mpTeamApplyMapper.insertMpTeamApply(mpTeamApply);
    }

    /**
     * 修改【商城用户】
     * 
     * @param mpTeamApply 【商城用户】
     * @return 结果
     */
    @Override
    public int updateMpTeamApply(MpTeamApply mpTeamApply)
    {
        mpTeamApply.setApprovalTime(new Date());
        mpTeamApply.setOptUser(SecurityUtils.getUsername());
        if(mpTeamApply.getApprovalStatus().equals("201")){
            MpClient client = mpClientMapper.selectMpClientByClientId(mpTeamApply.getClientId());
            client.setTeamConfigId(mpTeamApply.getTeamConfigId());
            if(client.getIsInstitutions()==1){
                client.setIsCert(1);
            }
            mpClientMapper.updateMpClient(client);
        }
        return mpTeamApplyMapper.updateMpTeamApply(mpTeamApply);
    }

    /**
     * 批量删除【商城用户】
     * 
     * @param teamApplyIds 需要删除的【商城用户】主键
     * @return 结果
     */
    @Override
    public int deleteMpTeamApplyByTeamApplyIds(Long[] teamApplyIds)
    {
        return mpTeamApplyMapper.deleteMpTeamApplyByTeamApplyIds(teamApplyIds);
    }

    /**
     * 删除【商城用户】信息
     * 
     * @param teamApplyId 【商城用户】主键
     * @return 结果
     */
    @Override
    public int deleteMpTeamApplyByTeamApplyId(Long teamApplyId)
    {
        return mpTeamApplyMapper.deleteMpTeamApplyByTeamApplyId(teamApplyId);
    }
}
